package com.tuyue.police.dao;

import com.tuyue.police.pojo.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/3/13.
 * @Modified By:
 */
public interface IUserDao extends JpaRepository<User,Long> {

    User findByUserName(String userName);

    User findByUserOpenId(String openId);

    @Query(value = "SELECT u.* FROM\n" +
            "  user AS u INNER JOIN rule2 AS r2 ON (u.user_id=r2.rule2_user_id) INNER JOIN rule AS r ON (r.rule_id=r2.rule2_rule_id)\n" +
            "WHERE r.rule_id=?1",nativeQuery = true)
    List<User> findAllByRuleId(Long ruleId);

    @Query(value = "SELECT u.* FROM user AS u INNER JOIN enterprise AS e ON (u.user_id=e.e_user_id) INNER JOIN device AS d ON (e.e_id=d.device_enterprise_id) INNER JOIN sector AS s ON (d.device_id=s.sector_device_id) WHERE s.sector_id=?1",nativeQuery = true)
    User findBySectorId(Long sectorId);
}
